package demo.util;

import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * Environment是在Spring中代表当前运行的环境，包括：profiles和properties,
 * 它继承了PropertyResolver接口所以才具有读取配置的功能：
 */
@Component
public class EnvironmentUtil implements EnvironmentAware {

    private static Environment env;

    @Override
    public void setEnvironment(Environment environment) {
        env = environment;
    }

    public static String getProperty(String key) {
        return env.getProperty(key);
    }

}
